'''
机动车驾驶人员意外伤害保险（2014 版）
'''

import sys

sys.path.append('../')
from common.config import *
from db.mysql import MysqlClient
from itertools import product


class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "机动车驾驶人员意外伤害保险（2014 版）"

    # 生成产品信息
    def genProductInfo(self):
        # 飞机乘客意外伤害身故、残疾
        planet = ["0", "10", "20", "30", "40", "50", "100"]
        # 火车乘客意外伤害身故、残疾
        train = ["0", "5", "10", "20", "30", "50"]
        # 轮船乘客意外伤害身故、残疾
        ship = ["0", "5", "10", "20", "30", "50"]
        # 客运汽车乘客意外伤害身故、残疾
        car = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "10", "20"]
        # 驾驶非营业机动车意外伤害身故
        car_die = ["0", "0.5", "1", "2", "3", "5", "6", "8", "10"]
        # 驾驶非营业机动车意外伤害残疾
        car_injured = ["0", "0.5", "1", "2", "3", "5", "6", "8", "10"]
        # 保险期间
        interval = [str(i) for i in range(1, 13)]

        for v in product(planet, train, ship, car, car_die, car_injured, interval):
            self.mysql.cursor.execute(domain[self.name]["insert_sql"].format(v[0], v[1], v[2], v[3], v[4], v[5], v[6]))

            self.mysql._conn.commit()

            print("%s写入数据库成功" % self.name)


if __name__ == '__main__':
    s = Spider()

    s.genProductInfo()
